/**
 * @file
 * This file contains global macros usefull across the project
 */

#ifndef __UTIL_H
#define __UTIL_H

#ifndef NULL
# define NULL ((void*)0)
#endif

/**
 * get_super_struct - get the struct for this member
 * @ptr:the &struct list_head pointer.
 * @type:the type of the struct this is embedded in.
 * @member:the name of the list_struct within the struct.
 */
#define get_super_struct(ptr, type, member) \
 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

/**
 * exassert - assert when condition is false
 * @cond:the condition to be evaluated
 */
#define exassert(cond) assert(cond)

/**
 * unused - mark unused variables to supress warnings
 * @name:the variable name
 */
#define unused(name) ((void)name)

/**
 * array_size - get the size of the array pointed to by a
 * @a:the array declared lyke "type a[10]"
 */
#define array_size(a) ((int)(sizeof(a)/sizeof((a)[0])))

/**
 * xchg - exchange a with b (a and b must have the same type)
 * @a:left operand to replace
 * @b:right operand to replace
 */
#define xchg(a, b) { typeof(a) __aux__; __aux__ = a; a = b; b = __aux__; }

/**
 * sgn - get the sign of a
 * @a:number to test the sine for
 */
#define sgn(a) ((a) < 0 ? 1 : 0)

/**
 * kb - tranform to KB from bytes
 * @a:number of bytes
 */
#define kb(a) ((a)/1024)

/**
 * abs - get the posisitive value of a
 * @a:number to be evaluated
 */
#define abs(a)  ((a) < 0 ? (-a) : (a))

/** true - return C true value */
#define TRUE  (0 == 0)

/** false - return C false value */
#define FALSE (0 == 1)

/** success - return process exit code success 0 */
#define SUCCESS (0)

/** failure - return process exit code error 1 */
#define FAILURE (1)

#endif /* __UTIL_H */
